//
//  MyViewController.m
//  WGFGlobalHouse
//
//  Created by waiguofang on 15/4/15.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//   经销商－－我的

#import "MyViewController.h"
#import "UIView+tapAction.h"
#import "BusinessViewController.h"
#import "MoneyViewController.h"
#import "BrokerAccountViewController.h"
#import "StoreViewController.h"
#import "SettingsViewController.h"
#import "AboutViewController.h"
#import "InfoViewController.h"
#import "photoTips.h"
#import "UIView+tapAction.h"
#import <MobileCoreServices/MobileCoreServices.h>
#define MAINHEIGHT 543/480.0*UIScreenHeight

@interface MyViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
//信息管理
@property (weak, nonatomic) IBOutlet UIView *infoView;

@property (weak, nonatomic) IBOutlet UIScrollView *mainScrollView;
//交易管理
@property (weak, nonatomic) IBOutlet UIView *businessView;
//佣金管理
@property (weak, nonatomic) IBOutlet UIView *moneyView;
//经纪人账号管理
@property (weak, nonatomic) IBOutlet UIView *middleManView;
//门店管理
@property (weak, nonatomic) IBOutlet UIView *storeView;
//系统设置
@property (weak, nonatomic) IBOutlet UIView *systemView;
//关于我们
@property (weak, nonatomic) IBOutlet UIView *aboutUsView;


//已成交订单
@property (weak, nonatomic) IBOutlet UIView *orderLab;
//已结佣金
@property (weak, nonatomic) IBOutlet UILabel *moneyLab;
//入住门店数
@property (weak, nonatomic) IBOutlet UILabel *storeLab;
//入住的经纪人数
@property (weak, nonatomic) IBOutlet UILabel *middleManLab;

@property (strong, nonatomic) NSArray *imgNameArr;
@property (weak, nonatomic) IBOutlet UIImageView *peopleImg;

@property (weak, nonatomic) photoTips *photoTips;

@property (weak, nonatomic) UIView *grayView;
@property(nonatomic,assign) BOOL isUpload;

@end

@implementation MyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.titleView setMianTitle:@"我的"];
    self.titleView.doneBtn.hidden = YES;

    self.mainScrollView.frame = CGRectMake(0, 0, self.view.frame.size.width, MAIN_SCREEN_bounds.size.height);
    [self.mainScrollView setContentSize:CGSizeMake(self.view.frame.size.width,MAINHEIGHT)];
    [self pushToOtherVC];
    
    [self addtapGestureToPeopleImg];
    self.isUpload = NO;
}

/**
 *  给头像添加手势
 */
-(void)addtapGestureToPeopleImg
{
    self.peopleImg.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(getPhoto)];
    [self.peopleImg addGestureRecognizer:tap];
}


/**
 *  点击“上传照片”获取照片
 */
-(void)getPhoto
{
    
    CGFloat height = UIScreenHeight*(132/480.0);
    CGFloat Y = UIScreenHeight - height;
    
    UIView *grayView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, UIScreenWidth, Y)];
    [grayView setBackgroundColor:[UIColor grayColor]];
    grayView.alpha = 0.5;
    self.grayView = grayView;
    [self.grayView addTapGestureWithTarget:self action:@selector(hiddenGrayView)];
    [self.view addSubview:self.grayView];
    
    
    photoTips  *view = [[[NSBundle mainBundle]loadNibNamed:@"photoTips" owner:nil options:nil]lastObject];
    view.frame = CGRectMake(0, Y, UIScreenWidth, height);
    self.photoTips = view;
    [self.view addSubview:self.photoTips];
    
    [self.photoTips.photoBtn addTapGestureWithTarget:self action:@selector(takePicture)];
    [self.photoTips.imageBtn addTapGestureWithTarget:self action:@selector(selectFromImage)];
    
}


-(void)takePicture
{
    UIImagePickerController *pc = [[UIImagePickerController alloc]init];
    pc.delegate = self;
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        pc.allowsEditing = YES;
        [self presentViewController:pc animated:YES completion:nil];
    }else
    {
        UIAlertView  *alter = [[UIAlertView alloc]initWithTitle:@"提示" message:@"相机不可用" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alter show];
    }

}

-(void)selectFromImage
{
    UIImagePickerController *pc = [[UIImagePickerController alloc]init];
    pc.delegate = self;
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
    {
        [pc setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
        pc.allowsEditing = YES;
        [self presentViewController:pc animated:YES completion:nil];
    }
    else{
        UIAlertView  *alter = [[UIAlertView alloc]initWithTitle:@"提示" message:@"相册不可用" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alter show];
        
    }

}


#pragma mark imagePickerController的代理
/**
 *  选择照片完成
 */
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;
{
    self.isUpload = YES;
    NSString *str = [info objectForKey:UIImagePickerControllerMediaType];
    if ([str isEqualToString:(NSString *)kUTTypeImage])//是image
    {
        UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
        [self dismissViewControllerAnimated:YES completion:^{
            [[UIApplication sharedApplication]setStatusBarHidden:NO];
        }];
        self.peopleImg.image =image;
    }
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void)hiddenGrayView
{
    self.grayView.hidden = YES;
    self.photoTips.hidden = YES;
}

/**
 *  点击推送到其他的界面
 */
-(void)pushToOtherVC
{
    //推送到信息管理
    [self.infoView addTapGestureWithTarget:self action:@selector(pushInfoVC)];
    //推送到交易管理
    [self.businessView addTapGestureWithTarget:self action:@selector(pushBusinessVC)];
    //推送到佣金管理
    [self.moneyView addTapGestureWithTarget:self action:@selector(pushMoneyVC)];
    //推送到经纪人账号管理
    [self.middleManView addTapGestureWithTarget:self action:@selector(pushMiddleManVC)];
    //推送到门店管理
    [self.storeView addTapGestureWithTarget:self action:@selector(pushStoreVC)];
    //推送到系统设置
    [self.systemView addTapGestureWithTarget:self action:@selector(pushSystemVC)];
    //推送到关于我们
    [self.aboutUsView addTapGestureWithTarget:self action:@selector(pushAboutUsVC)];

}
/**
 * 推送到信息管理
 */
-(void)pushInfoVC
{
    InfoViewController *infoVC = [[InfoViewController alloc]initWithNibName:@"InfoViewController" bundle:nil];
    [self.navigationController pushViewController:infoVC animated:YES];
}
/**
 * 推送到交易管理
 */
-(void)pushBusinessVC
{
    BusinessViewController *businessVC = [[BusinessViewController alloc]initWithNibName:@"BusinessViewController" bundle:nil];
    [self.navigationController pushViewController:businessVC animated:YES];
}
/**
 * 推送到佣金管理
 */
-(void)pushMoneyVC
{
    MoneyViewController *moneyVC = [[MoneyViewController alloc]initWithNibName:@"MoneyViewController" bundle:nil];
    [self.navigationController pushViewController:moneyVC animated:YES];
}
/**
 * 推送到经纪人账号管理
 */
-(void)pushMiddleManVC
{
     BrokerAccountViewController *accountVC = [[BrokerAccountViewController alloc]initWithNibName:@"BrokerAccountViewController" bundle:nil];
    [self.navigationController pushViewController:accountVC animated:YES];
}
/**
 * 推送到门店管理
 */
-(void)pushStoreVC
{
    StoreViewController *storeVC = [[StoreViewController alloc]initWithNibName:@"StoreViewController" bundle:nil];
    [self.navigationController pushViewController:storeVC animated:YES];
}
/**
 * 推送到系统设置
 */
-(void)pushSystemVC
{
    SettingsViewController *settingVC = [[SettingsViewController alloc]initWithNibName:@"SettingsViewController" bundle:nil];
    [self.navigationController pushViewController:settingVC animated:YES];
}
/**
 * 推送到关于我们
 */
-(void)pushAboutUsVC
{
    AboutViewController *aboutUsVC = [[AboutViewController alloc]initWithNibName:@"AboutViewController" bundle:nil];
    [self.navigationController pushViewController:aboutUsVC animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}



@end
